package com.evil.kingdom.controller.world.region;

import com.evil.common.core.entity.R;
import com.evil.kingdom.pojo.entity.world.region.Region;
import com.evil.kingdom.service.world.region.RegionService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 地域
 *
 * @author liyang
 * @date 2024-05-22 17:11
 */
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/region")
public class RegionController {

    private final RegionService regionService;

    /**
     * 新增地域
     *
     * @param region region
     * @return R
     */
    @PostMapping("/add")
    public R<Region> add(@RequestBody @Validated Region region) {
        return R.success(regionService.add(region));
    }

    /**
     * 更新地域
     *
     * @param region region
     * @return R
     */
    @PostMapping("/update")
    public R<Region> update(@RequestBody @Validated Region region) {
        return R.success(regionService.update(region));
    }

    /**
     * 查询地域
     *
     * @param name name
     * @return R
     */
    @RequestMapping("/find-by-name")
    public R<Region> findByName(String name) {
        return R.success(regionService.findByName(name));
    }
}
